package com.seeqool.v1.chartframes;

import java.util.Enumeration;
import java.util.Hashtable;

import org.jfree.chart.ChartFactory;
import org.jfree.chart.ChartPanel;
import org.jfree.chart.plot.PlotOrientation;
import org.jfree.data.category.DefaultCategoryDataset;

import com.seeqool.v1.datamodel.SQLTable;

public class CategoryHistogramFrame extends BaseChartFrame {

	private static final long serialVersionUID = 1L;

	public CategoryHistogramFrame(SQLTable queryResult, int majorAxis) {
		super("Histogram");
		Hashtable<String,Integer> counts = new Hashtable<String, Integer>();
		for (int r=0; r<queryResult.getRowCount(); r++) {
			String key = queryResult.getValueAt(r, majorAxis).toString();
			if (counts.containsKey(key)) {
				counts.put(key, counts.get(key)+1);
			} else {
				counts.put(key, 1);
			}
		}
		Enumeration<String> keys=counts.keys();
		DefaultCategoryDataset cdata = new DefaultCategoryDataset();
		while (keys.hasMoreElements()) {
			String key = keys.nextElement();
			cdata.addValue(counts.get(key), "", key);
		}
		addContent(new ChartPanel(ChartFactory.createStackedBarChart("Test", "x", "y", cdata, PlotOrientation.HORIZONTAL, true, true, false)));
	}
	
}
